/*!
 * \class ThreadPool
 *
 * \brief 线程池
 *
 * \author Bryceyam
 * \date ʮһ�� 2025
 */
#pragma once
#include <thread>
#include <mutex>
#include <vector>
#include <list>
#include <atomic>
#include <memory>
#include "ThreadPool/globle.h"

#include "Task/Task.h"

class THREADPOOL_API ThreadPool
{
public:
	static ThreadPool& getInstance();
	
	bool init(int num);

	
	bool start();

	
	void stop();

	
	void addTask(std::shared_ptr<Task> task);

	
	std::shared_ptr<Task> getTask();

	bool isExit();

	int getTaskCount();


private:
	
	void run();

	ThreadPool() {};


	int mThreadNum = 0;//线程数
	std::mutex mMux;
	std::vector<std::shared_ptr<std::thread>> mThreadList;//线程列表
	std::list< std::shared_ptr<Task>> mTaskList;//任务列表
	std::condition_variable mCv;
	bool mIsExit = false;
	std::atomic<int> mTaskCount = 0;
};

#define  THREADPOOL ThreadPool::getInstance()